package nl.rug.ml.dobbelen.agent;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

import nl.rug.ml.dobbelen.game.Dice;

public class DobbelenHumanPlayer extends DobbelenAgent {

	public DobbelenHumanPlayer(int numDice) {
		super(numDice);
	}

	@Override
	public void throwDices() {
		super.throwDices();
		printDices();
		System.out.printf("Score: %d Total: %d\n", getCurrentScore(), getTotalScore());
	}

	@Override
	public boolean reThrowDices(List<Dice> heldDices) {
		boolean success = super.reThrowDices(heldDices);
		printDices();
		System.out.printf("Score: %d Total: %d\n", getCurrentScore(), getTotalScore());
		return success;
	}

	@Override
	public boolean willReThrow() {
		System.out.print("Do you want to throw again (Y/N)? ");
		Scanner sc = new Scanner(System.in);
		String decision = sc.next();
		if (decision.equalsIgnoreCase("y")) {
			return true;
		}
		else if (decision.equalsIgnoreCase("n")) {
			return false;
		}
		else {
			return willReThrow();
		}
	}

	@Override
	public List<Dice> chooseDicesToHold() {
		System.out.print("Dices to be held? ");
		List<Dice> holdDices = new LinkedList<Dice>();
		Scanner sc = new Scanner(System.in);
		String answer = sc.nextLine();
		if (!answer.isEmpty()) {
			String[] indexes = answer.split("\\s");
			for (String s : indexes) {
				holdDices.add(dices.get(Integer.parseInt(s)));
			}
		}
		return holdDices;
	}

}
